﻿@{
    Layout = null;
    MICZ.CodeBuilder.ViewModels.WorkContent WorkContent = ViewBag.WorkContent;
}
@using MICZ.CodeBuilder.IRepository.SqlSugar;
@inject ISqlSugarRepository SqlSugarRepository;
<script src="@WorkContent.ThemePath/js/jquery-3.4.1.min.js"></script>
<link href="@WorkContent.ThemePath/layui/css/layui.css" rel="stylesheet" />
<script src="@WorkContent.ThemePath/layui/layui.js"></script>
<script src="@WorkContent.ThemePath/bais.js"></script>

<blockquote class="layui-elem-quote">@ViewData["title"]</blockquote>

<blockquote class="layui-elem-quote">
    <div class="layui-inline">
        <span>命名空间:</span>
        <div class="layui-input-inline">
            <input id="namespace" type="text" value="" placeholder="请输入命名空间" class="layui-input" />
        </div>
    </div>
    <div class="layui-inline">
        <button id="interface" type="button" class="layui-btn layui-inline" onmouseover="Tips()">一键生成项目</button>
    </div>
</blockquote>
<script>
    if (localStorage.getItem("namespace") != null)
        $("#namespace").val(localStorage.getItem("namespace"));
    else {
        $.ajax({
            type: "GET",
            url: "/ManageAPI/Builder/Namespace",
            //data: { "ID": (obj.data).ID },
            dataType: "json",
            headers: header,
            success: function (data) {
                if (data.Status) {
                    $("#namespace").val(data.ResData)
                    localStorage.setItem("namespace", $("#namespace").val());
                }
            },
            error: function (data) {
            }
        });
    }
    (function () {
        $("#namespace").on("change", function () {
            localStorage.setItem("namespace", $("#namespace").val());
            //代码获取
            $.ajax({
                type: "GET",
                url: "/ManageAPI/Builder/NamespaceEdit?text=" + $("#namespace").val(),
                //data: { "ID": (obj.data).ID },
                dataType: "json",
                headers: header,
                success: function (data) {
                },
                error: function (data) {
                }
            });
        });
        $("#interface").on("click", function () {
            //代码获取
            $.ajax({
                type: "GET",
                url: "/ManageAPI/Builder/Project?Type=Register&text=" + $("#namespace").val(),
                //data: { "ID": (obj.data).ID },
                dataType: "json",
                headers: header,
                success: function (data) {
                    layui.layer(data.Msg);
                },
                error: function (data) {
                    layui.layer(data);
                }
            });
        });
    })();
</script>

<div class="layui-row">
    <div class="layui-col-xs12 layui-col-sm12 layui-col-md12" style="height:100%;">
        <div class="layui-tab layui-tab-brief" lay-filter="demoTitle">
            <ul class="layui-tab-title site-demo-title">
                <li class="layui-this">Register代码</li>
            </ul>
            <div class="layui-body layui-tab-content site-demo site-demo-body" style="left: 0px;top: 60px;right: unset;bottom: unset;">
                <!-- 第三个选项卡 -->
                <div class="layui-tab-item layui-show">
                    @*代码预览*@
                    @*<button type="button" class="layui-btn layui-btn-xs layui-btn-normal">保存代码</button>
                        <button type="button" class="layui-btn layui-btn-xs layui-btn-warm">下载代码</button>*@
                    @*<button type="button" class="layui-btn layui-btn-danger">警告按钮</button>*@
                    <pre class="layui-code" id="layui-code-Register">      </pre>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    //console.log("jiazai");
    var layer = null;
    layui.use(['code', 'layer', 'element'], function () {
        layer = layui.layer;
        OnTableColumns();

        layui.code();
        var element = layui.element;
        //触发事件
        element.on('tab(demoTitle)', function (elem) {
            location.hash = 'test=' + $(this).attr('lay-id');
        });
    });
    function Tips(Type) {//小提示
        if (Type != 1 && Type != 2)
            return;
        let id = "#interface";
        let tip = "注入层";
        layer.tips(tip, id, {
            tips: [1, '#3595CC'],
            time: 1000
        });
    }

    function OnTableColumns() {
        $.ajax({
            type: "GET",
            url: "/ManageAPI/Builder/Index?Type=Register",
            //data: { "ID": (obj.data).ID },
            dataType: "json",
            headers: header,
            success: function (data) {
                if (data.Status == 1) {
                    $("#layui-code-Register").html(data.Data.Obj);
                    layui.code({
                        elem: '#layui-code-Register' //默认值为.layui-code
                        , title: 'BuliderCode'
                    });
                }
            },
            error: function (data) {
                layer.alert("提交出现了错误！");
            }
        });
    };
</script>
